<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE HTML>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<base href="<%=basePath%>">
<html lang="zn-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no"/>
    <title>我的</title>
    <link rel="stylesheet" href="css/base.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/base.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script type="text/javascript" src="js/handle.js"></script>
</head>
<body>
<div class="wrap">
    <div class="mine_top_layer">
        <img class="avatar" src="http://111.231.253.134/static/common/img/mp/avatar.jpg" id="filePicker">
        <p class="identity"></p>
        <h4>
            <span class="coins"></span>
        </h4>
    </div>
    <div class="mine_menu">
        <p onclick="javascript:window.location.href = 'wxmp/user/toDetail'">
            <img class="cardbag" src="img/id.png">
            个人信息
            <span class="arrow"></span>
        </p>
        <p onclick="javascript:window.location.href = 'wxmp/group/toGroup'">
            <img class="cardbag" src="img/calendar_blue.png">
            所在团队
            <span class="arrow"></span>
        </p>
        <p onclick="javascript:window.location.href = 'wxmp/yellow/toGroup?memberNum=${userInfo.data.memberNum}'">
            <img class="cardbag" src="img/calendar_red.png">
            关注团队
            <span class="arrow"></span>
        </p>
        <p onclick="javascript:window.location.href = 'wxmp/user/toUpdatePSW'">
            <img class="resetPsw" src="img/lock.png">
            修改密码
            <span class="arrow"></span>
        </p>
        <p onclick="javascript:window.location.href = 'wxmp/user/logout'">
            <img class="exit" src="img/exit_red.png">
            退出登录
            <span class="arrow"></span>
        </p>
    </div>
    <div class="toast toast_timeout" style="display:none">网络异常，请稍后重试！</div>
    <div class="toast toast_error" style="display:none">信息输入有误</div>
</div>
<div class="info"></div>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script type="text/javascript" src="js/weixin.js"></script>
<script type="text/javascript">
    var jsApiList = ['checkJsApi','chooseImage','previewImage','uploadImage','hideAllNonBaseMenuItem']//该数组有不定数量的元素，元素可能是方法、字符串等等
    getSignature(jsApiList,function () {
        wx.hideAllNonBaseMenuItem();
    });
    //发送图片id到后台
    function sendImgID(id) {
        $.ajax({
            url:  $.httpRootPath()+'rest/user/userPhoto',
            type: 'POST',
            dataType: 'json',
            data: {
                media_id: id
            },
            timeout: 20000,
            success: function (r) {
                console.log(r);
                if (r.code != "00") {
                    errorToast("上传异常,请稍后再试", 3);
                    return false;
                }else {
                    $('#filePicker').attr('src', r.data.picture);
                }
            },
            error: function (e) {
                errorToast("头像修改失败，请稍后再试！",3)
            }
        });
    }
    // 上传图片
    var syncUpload = function (localIds) {
        var localId = localIds.pop();
        wx.uploadImage({
            localId: localId,
            isShowProgressTips: 1,
            success: function (res) {
                var serverId = res.serverId; // 返回图片的服务器端ID
                //其他对serverId做处理的代码
                if (localIds.length > 0) {
                    syncUpload(localIds);
                }
                sendImgID(serverId);
            }
        });
    };
    $(function () {
        $('#filePicker').on('click', function () {
            wx.chooseImage({
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {
                    var localIds = res.localIds;
                    console.log(localIds)
                    syncUpload(localIds);
                }
            });
        });
    })

</script>
<script>
    var userInfo = ${result}
    var wxMpUser = ${wxMpUser};
    $(".coins").html(userInfo.data.memberNum);
    if(userInfo.data.picture != ''){
        $("#filePicker").attr("src",userInfo.data.picture);
    }else{
        if (wxMpUser.headImgUrl = ""){
            $("#filePicker").attr("src",wxMpUser.headImgUrl);
        }
    }
</script>
</body>
</html>
